<?php
declare (strict_types=1);

namespace app\common\model\questionnaire;

use cores\BaseModel;

/**
 * 问卷题目记录表模型
 * Class Topic
 * @package app\common\model\questionnaire
 */
class Topic extends BaseModel
{
    // 定义表名
    protected $name = 'questionnaire_topic';

    // 定义主键
    protected $pk = 'topic_id';

    /**
     * 追加字段
     * @var array
     */
    protected $append = [];

    /**
     * 详情
     * @param $where
     * @param array $with
     * @return array|static|null
     */
    public static function detail($where, array $with = [])
    {
        return static::get($where, $with);
    }

    public function getItemsAttr($value)
    {
        return $value ? json_decode($value, true) : [];
    }

    public function getCorrectAnswerAttr($value)
    {
        return $value ? explode(',', $value) : [];
    }
}
